package com.wwg.market.ui.service.interfaces;

import com.wwg.market.ui.service.dto.AttributeDto;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: Tom
 * Date: 2011-12-7
 * Time: 9:24:20
 * To change this template use File | Settings | File Templates.
 */
public class ProductAttributeServiceImpl implements ProductAttributeService {
    public List<AttributeDto> getAttributeByCategory(Long categoryId) {
        List result = new ArrayList();
        for (int i = 0; i < ((int) (Math.random() * 8)); i++) {
            AttributeDto dto = new AttributeDto();
            dto.setName("属性" + i + categoryId);
            dto.setRequired(i % 2 == 0);
            dto.setType(i % 2 + "");
            dto.setDescription("描述" + i + categoryId);
            result.add(dto);
        }
        return result;
    }

    public AttributeDto saveAndUpdate(AttributeDto dto) {
        if (dto.getId() == null) {
            AttributeDto dto2 = new AttributeDto();
            dto2.setId(new Long((long) (Math.random() * 1000)));
            dto2.setName(dto.getName());
            dto2.setRequired(dto.getRequired());
            dto2.setType(dto.getType());
            dto2.setDescription(dto.getDescription());
            return dto2;
        } else
            return dto;
    }

    public void delete(AttributeDto dto) {

    }
}
